<template>
  <div class="login-wrapper">
    <div class="modal">
      <el-form ref="userForm" :model="user" status-icon :rules="rules">
        <div class="title">八维权限管理系统</div>
        <el-form-item prop="LoginEMail">
          <el-input
            type="text"
            prefix-icon="el-icon-user"
            v-model="user.LoginEMail"
            placeholder="请输入邮箱"
          />
        </el-form-item>
        <el-form-item prop="LoginPass">
          <el-input
            type="password"
            prefix-icon="el-icon-view"
            v-model="user.LoginPass"
            placeholder="请输入密码"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="btn-login" @click="login"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import $http from '../request/http'
export default {
  name: "login",
  data() {
    return {
      user: {
        LoginEMail: "",
        LoginPass: "",
      },
      rules: {
        LoginEMail: [
          {
            required: true,
            message: "请输入邮箱",
            trigger: "blur",
          },
        ],
        LoginPass: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    login() {
      this.$refs.userForm.validate((valid) => {
        if (valid) {
          $http.post('Login/Login',this.user).then((res) => {
              console.log(res.data);
           if (res.data.Code==200) {
               //存储用户ID
                localStorage.setItem("userid",res.data.Data.UserId)
                //存储token
                localStorage.setItem("token",res.headers.token)
                this.$router.push("/system/user");
                
           }else{
               this.$message.error(res.data.Message);
           }
          });
        } else {
          return false;
        }
      });
    },
    
  },
};
</script>

<style  scope>
.login-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f9fcff;
  width: 100vw;
  height: 100vh;
 
}
 .modal {
    width: 500px;
    padding: 50px;
    background-color: #fff;
    border-radius: 4px;
    box-shadow: 0px 0px 10px 3px #c7c9cb4d;
  
  }

  .title {
      font-size: 50px;
      line-height: 1.5;
      text-align: center;
      margin-bottom: 30px;
    }
    
.btn-login {
      width: 100%;
    }
</style>